#include "misc_dialog.h"

#include <QGroupBox>
#include <QHBoxLayout>
#include <QPushButton>
#include <QCheckBox>
#include <QVBoxLayout>

#include "core/music_settings.h"

MiscDialog::MiscDialog(MusicSettings *settings, QWidget *parent):
  QDialog(parent),
  settings(settings) {
  setWindowTitle("Divers");
  QGroupBox *miscBox = new QGroupBox("Divers", this);
  QVBoxLayout *miscBoxLayout = new QVBoxLayout;
  miscBox->setLayout(miscBoxLayout);

  conjoint = new QCheckBox("Notes &conjointes", this);
  miscBoxLayout->addWidget(conjoint);

  noRepetition = new QCheckBox("Pas de note &répétée", this);
  miscBoxLayout->addWidget(noRepetition);

  // boutons

  QPushButton *okButton = new QPushButton("&Valider", this);
  connect(okButton, SIGNAL(clicked()), this, SLOT(validate()));

  QPushButton *cancelButton = new QPushButton("&Annuler", this);
  connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));

  QHBoxLayout *buttonLayout = new QHBoxLayout;
  buttonLayout->addStretch();
  buttonLayout->addWidget(okButton);
  buttonLayout->addWidget(cancelButton);

  //

  QVBoxLayout *mainLayout = new QVBoxLayout;
  mainLayout->addWidget(miscBox);
  mainLayout->addLayout(buttonLayout);
  setLayout(mainLayout);

  initialize();
}

/*!
 * Initialise les cases en fonction des paramètres
 */
void MiscDialog::initialize() {
  conjoint->setChecked(settings->conjoint);
  noRepetition->setChecked(settings->noRepetition);
}

/*!
 * Change les paramètres puis ferme la fenêtre
 */
void MiscDialog::validate() {
  settings->conjoint = conjoint->isChecked();
  settings->noRepetition = noRepetition->isChecked();

  close();
}

